<?php 

require_once ('Zend/Controller/Plugin/Abstract.php');

class App_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
	/** 
	 * 
	 * 
	 * @see Zend_Controller_Plugin_Abstract::preDispatch()
	 */
	public function preDispatch(Zend_Controller_Request_Abstract $request) 
	{
		if ( ( $request->getModuleName() == 'safety' && $request->getControllerName() == 'login') 
			||
			( $request->getModuleName() == 'website' ) )
		{ 
			return true; 
		}
		
		$acl = new App_Acl();
		if ($acl->isAllowed(Zend_Auth::getInstance()->getIdentity(), $request, null) === false) {
			$request->setModuleName('safety')
					->setControllerName('login')
					->setActionName('login')
					->setDispatched(false);
			return false;
		}		
	}
}